/**
	License:		Artistic license 2.0 (see license.txt, also available online at http://www.perlfoundation.org/artistic_license_2_0)
	Authors:		OrbitalLab (http://www.orbitallab.ru/moonglide/), 2007-2009

	File:			IScene.d
	Description:	scene interface
	Date:			11.04.2008 by Digited
*/
module moonglide.scenes.IScene;

import
	moonglide.core.Events,

	moonglide.core.engobjects.EngObject,
	moonglide.core.engobjects.EngCamera,

	moonglide.scenes.rendertarget.Main,

///!!!!	moonglide.gui.GuiBasic,

	moonglide.resources.resobjects.hilevel.ResMaterial,
	moonglide.renderer.IRendererOffscreen;

public import moonglide.io.Config;

//================================================================
/**
	Scene in MoonGlide doesn't have just one object tree (scenegraph), but instead it has 1 or more layers,
	that own other objects and so make object trees with self as root. So, each layer is a separated scenegraph
	with its own active camera and material.

	The main purpose of layers is to separate groups of objects, like "background", "foreground", "GUI",
	"HUD" - all these scene abstractions can be individually rendered from one scene via scene
	layers with their specisal projection parameters (via layer camera) and material parameters.

	Layers are processed and passed to renderer subsystem in order of their indexes in scene
	layers array: layers[0] is first etc.

	When processing scene, scene manager works only with layers, not with scene tree inself,
	so:
	1. there must be at least one layer that contains at least one renderable object
	and a camera, or there'll be no rendering at all.
	2. cameras are not counted as renderable object, they "work" only being a layer camera.
*/
//================================================================
class CSceneLayer : public CEngObject
{
    protected:
		IRenderTarget	    _renderTarget;
	public:
		CEngCamera			camera;
		CResMaterial		material;


		void setRenderTarget( IRenderTarget tar )
		{
            _renderTarget = tar;
		}

		this( char[] id, CEngCamera cam, CResMaterial mat )
		{
			super( id );
			camera = cam;
			material = mat;
			parent = this; // self-parented!
			isStatic = true;

			addChild( camera );
		}
}

//================================================================
/// IScene interface
//================================================================
interface IScene : IEventListener, IEventGenerator
{
	//CGUIManager		guiManager();
	CSceneLayer[]	layers();
	CEngCamera[]	cameras();

	void			loadConfig();	// added because scenes are constructed before definition of program path driver in MoonFile
	CConfig			getConfig();

	bool			initialized();
	bool			initialize();
	void			run( float frametime );
	void			shutdown();

	void			onEventCallback( CEvent event, IEventGenerator gen );
}
